#include <boost/regex.hpp>
#include "ResponseManager.h"

namespace http {
  http::Response* ResponseManager::GetResponseObj(const std::string &body, const std::string &header) {
    boost::regex pattern("Content-Type:\\s*([a-zA-Z0-9\\/-]+)");
    boost::smatch matches;

    std::string::const_iterator begin = header.begin();
    std::string content_type("text/xml");
    while(boost::regex_search(begin, header.end(), matches, pattern)) {
      content_type = std::string(matches[1].first, matches[1].second);
      begin = matches[1].second;
    }

    if(content_type == "text/xml")
      return new XMLResponse(body, header);
    else
      return new Response(body, header);
  }
}
